package top.frsf.starter.impl;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import top.frsf.constants.ImageConstant.Home;
import top.frsf.enums.GameStateEnum;
import top.frsf.panel.GamePanel;
import top.frsf.starter.Starter;

import javax.imageio.ImageIO;
import java.awt.*;
import java.io.File;

/**
 * 主页场景启动器
 *
 * @author He Kuntao
 * @since 2025/8/6 9:26
 */
@Data
@Slf4j
public class HomeStarter implements Starter {
    /* 场景图片 */
    private Image MAIN_RIGHT;
    private Image MAIN_LEFT;
    private Image MAIN_CENTER;
    private Image MAIN_TOP;
    private Image ADVENTURE_BUTTON;
    private Image LIGHT_ADVENTURE_BUTTON;
    private Image BLOCK;
    private Image OPTION;
    private Image HELP;
    private Image QUIT;
    private Image LEAVES;

    /* 游戏属性 */
    // 冒险模式按钮矩形
    private Rectangle adventureButton = new Rectangle(515, 126, 300, 100);
    // 冒险模式按钮图像高亮切换
    private boolean isAdventureLight = false;

    @Override
    public void init() {
        log.info("主页启动器初始化");
        try {
            MAIN_RIGHT = ImageIO.read(new File(Home.MAIN_RIGHT));
            MAIN_LEFT = ImageIO.read(new File(Home.MAIN_LEFT));
            MAIN_CENTER = ImageIO.read(new File(Home.MAIN_CENTER));
            MAIN_TOP = ImageIO.read(new File(Home.MAIN_TOP));
            ADVENTURE_BUTTON = ImageIO.read(new File(Home.ADVENTURE_BUTTON));
            LIGHT_ADVENTURE_BUTTON = ImageIO.read(new File(Home.LIGHT_ADVENTURE_BUTTON));
            BLOCK = ImageIO.read(new File(Home.BLOCK));
            OPTION = ImageIO.read(new File(Home.OPTION));
            HELP = ImageIO.read(new File(Home.HELP));
            QUIT = ImageIO.read(new File(Home.QUIT));
            LEAVES = ImageIO.read(new File(Home.LEAVES));
        } catch (Exception e) {
            log.error("主页场景启动器初始化失败");
            throw new RuntimeException(e);
        }
    }

    @Override
    public void start(Graphics g) {
        if (GamePanel.state == GameStateEnum.HOME) {
            g.drawImage(MAIN_TOP, 0, 0, 900, 600, 0, 0, 100, 75, null);
            g.drawImage(MAIN_CENTER, 50, 250, 780, 600, 0, 0, 720, 350, null);
            g.drawImage(MAIN_RIGHT, 163, 70, null);
            g.drawImage(MAIN_LEFT, 0, 0, null);
            g.drawImage(BLOCK, 0, 20, null);
            g.drawImage(OPTION, 650, 520, null);
            g.drawImage(HELP, 740, 550, null);
            g.drawImage(QUIT, 815, 540, null);
            g.drawImage(LEAVES, 300, 580, null);
            g.drawImage(isAdventureLight ? LIGHT_ADVENTURE_BUTTON : ADVENTURE_BUTTON, 500, 120, null);
            g.setColor(Color.white);
            g.setFont(new Font("Arial", Font.BOLD, 20));
            g.drawString("FRSF", 130, 130);
        }
    }
}
